<?php
/**
 * author        : ${USER}
 * createTime    : 2021/11/14 13:53
 * version       : 1.0
 * filename      : OrderResource.php
 */

namespace App\Http\Resources;

use DB;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class OrderResource extends JsonResource
{
    /**
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        return parent::toArray($request) + [
                'latestorderitems' =>
                    DB::select('select * from xhp_orderdetails as b where created_at in(
select b.m from (
select max(created_at) as m ,product_id from xhp_orderdetails group by product_id
) as b
)')
            ];
    }
}